package cnsatmsmart.automation.mmi.model.data.TSafe;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * @author SIK - PTIK, BPPT
 **/

public class Route {    //based on TSafe
    /* atribut - atribut yang dimiliki oleh kelas Route */
        private List fixes; //senarai dari fix yang dilalui dalam route terkait

    /* constructor */
        // <editor-fold defaultstate="collapsed" desc="ctor">
        /*
         * @param = atribut
         */
        public Route () {           //default ctor
            this.fixes = new LinkedList();
        }
        public Route (Route r) {    //user defined ctor - cctor
            this.fixes = new LinkedList(r.getFixes());
        }
        // </editor-fold>

    /* getter */
        public List getFixes () {
            /* mengembalikan nilai dari atribut fixes */
            return (this.fixes);
        }

    /* method - method yang dimiliki oleh kelas Route */
        public boolean isEmpty () {
            return (this.fixes.isEmpty());
        }
        public void addFix (Fix f) {
            this.fixes.add(f);
        }
        public Fix firstFix () {
            if (this.isEmpty()) {
                throw new NoSuchElementException("empty route");
            } else {
                return ((Fix)this.fixes.get(0));
            }
        }
        public Fix lastFix () {
            if (this.isEmpty()) {
                throw new NoSuchElementException("empty route");
            } else {
                return ((Fix)this.fixes.get(this.fixes.size() - 1));
            }
        }
        public List fixesList () {
            return (Collections.unmodifiableList(this.fixes));
        }
        public Iterator fixesIterator () {
            return (this.fixes.iterator());
        }

    @Override
    public String toString () {
        StringBuilder strBuildr = new StringBuilder();
        Iterator fixesIter = this.fixesIterator();
        while (fixesIter.hasNext()) {
            strBuildr.append(fixesIter.next());
            if (fixesIter.hasNext()) {
                strBuildr.append(".");
            }
        }

        return (strBuildr.toString());
    }
}
